<template>
  <div>
    <div style="display: flex;font-weight: bold;color: #000000;justify-content: center;font-size: 29px;padding: 20px">
      江西省地方标准
    </div>
    <div
      style="display: flex;font-weight: bold;color: #000000;justify-content: center;font-size: 21px;margin-bottom: 10px;">
      项目申报表
    </div>
    <div
      style="display: flex;font-weight: bold;color: #000000;justify-content: center;font-size: 21px;margin-bottom: 10px;">
      （试行）
    </div>
    <t-form labelAlign="top" ref="form" :data="formData"  class="step-form table-form"
            labelWidth="140px">
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>项目名称</t-col>
        <t-col :span="4">
          <t-form-item name="projectName">
            {{ formData.projectName }}
          </t-form-item>
        </t-col>
        <t-col :span="2" class="title"><span class="require">*</span>提出日期</t-col>
        <t-col :span="4">
          <t-form-item name="putDate">
            {{ formData.putDate }}
          </t-form-item>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title">技术归口单位</t-col>
        <t-col :span="4">
          标准委员会
        </t-col>
        <t-col :span="2" class="title">中文名称</t-col>
        <t-col :span="4">
          {{ formData.projectName }}
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>英文名称</t-col>
        <t-col :span="4">
          <t-form-item name="englishName">
            {{ formData.englishName }}
          </t-form-item>
        </t-col>
        <t-col :span="2" class="title"><span class="require">*</span>批复立项时间</t-col>
        <t-col :span="4">
          <t-form-item name="replyDate">
            {{ formData.replyDate }}
          </t-form-item>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>标准性质</t-col>
        <t-col :span="10">
          <t-form-item name="standardProperty">
            {{ formData.standardProperty | filterByDict(dict.type.standard_property) }}
          </t-form-item>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>制定/修订</t-col>
        <t-col :span="4">
          <t-form-item name="formulateType">
            <t-radio-group :disabled="true" clearable v-model="formData.formulateType"
                           :options="dict.type.formulate_type">
            </t-radio-group>
          </t-form-item>
        </t-col>
        <t-col :span="2" class="title"><span class="require"
                                             v-if="formData.formulateType && formData.formulateType!=='1'">*</span>被修订标准号
        </t-col>
        <t-col :span="4">
          <t-form-item v-if="formData.formulateType && formData.formulateType!=='1'" name="formulateType">
            {{ formData.reviseNum }}
          </t-form-item>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>采标情况</t-col>
        <t-col :span="10" style="display:block;">
          <t-row>
            <t-col :span="2" class="sub-title"><span class="require">*</span>（1）采用国际标准：</t-col>
            <t-col :span="10">
              <t-form-item name="bidCondition.bidType">
                <t-radio-group :disabled="true" clearable v-model="formData.bidCondition.bidType"
                               :options="dict.type.bid_type">
                </t-radio-group>
              </t-form-item>
            </t-col>
          </t-row>
          <t-row>
            <t-col :span="2" class="sub-title"><span class="require" v-if="formData.bidCondition.bidType!=='1'">*</span>（2）采用程度：</t-col>
            <t-col :span="10">
              <t-form-item v-if="formData.bidCondition.bidType!=='1'" name="bidCondition.bidDegree">
                <t-radio-group :disabled="true" clearable v-model="formData.bidCondition.bidDegree"
                               :options="dict.type.bid_degree">
                </t-radio-group>
              </t-form-item>
            </t-col>
          </t-row>
          <t-row>
            <t-col :span="2" class="sub-title"><span class="require" v-if="formData.bidCondition.bidType!=='1'">*</span>（3）采标名称：</t-col>
            <t-col :span="10">
              <t-form-item v-if="formData.bidCondition.bidType!=='1'" name="bidCondition.bidName">
                {{ formData.bidCondition.bidName }}
              </t-form-item>
            </t-col>
          </t-row>
          <t-row>
            <t-col :span="2" class="sub-title"><span class="require" v-if="formData.bidCondition.bidType!=='1'">*</span>（4）采 标 号：</t-col>
            <t-col :span="10">
              <t-form-item v-if="formData.bidCondition.bidType!=='1'" name="bidCondition.bidNum">
                {{ formData.bidCondition.bidNum }}
              </t-form-item>
            </t-col>
          </t-row>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title">项目周期</t-col>
        <t-col :span="10">
          12个月
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>起草单位</t-col>
        <t-col :span="10">
          <standard-company ref="standard-company" tableSize="small" v-model="formData.draftUnits"
                            :editOpen="false"></standard-company>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>技术归口单位 （或技术委员会）</t-col>
        <t-col :span="10">
          标准委员会
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>主管部门</t-col>
        <t-col :span="10">
          {{ formData.manageDeptId | filterByTree(deptMenuOptions) }}
        </t-col>
      </t-row>

      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>制修订地方标准的必要性、可行性
          <t-tooltip
            content="【立项必要性包括但不限于：经济社会和产业发展的需求；相关法律法规、政策规划的要求；标准实施后重大经济、社会、生态效益分析。项目可行性包括但不限于：产业发展情况；有关技术的成熟度和经济性分析；如果实施标准对企业生产经营成本影响较大，应进行综合成本分析；已经具备的研究基础和条件等】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="necessity">
            <InnerHtml :content="formData.necessity"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>
      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>主要技术内容
          <t-tooltip content="【包括范围和主要技术内容等，修订项目应说明拟修订的内容，与原标准相比的主要变化。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="technicalContent">
            <InnerHtml :content="formData.technicalContent"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>
      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>国内外标准情况、与国际标准一致性程度情况
          <t-tooltip
            content="【包括国内相关标准情况，与拟制定标准的关系，范围包含但不限于相关国家标准、行业标准、地方标准、团体标准和企业标准；有关国际标准化组织、有关国家或地区的相关标准情况、主要内容；拟制定标准拟采用或参照哪些国际国外标准，并对一致性进行描述。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="description">
            <InnerHtml :content="formData.description"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>
      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>与相关强制性标准、法律法规配套情况
          <t-tooltip content="【包括国内有关强制性标准、法律法规情况，与拟制定标准的关系。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="relation">
            <InnerHtml :content="formData.relation"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>

      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>标准所涉及的产品、过程或者服务目录
          <t-tooltip content="【应尽可能详细列出所规范的产品、过程或服务的名称或清单。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="catalogue">
            <InnerHtml :content="formData.catalogue"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>

      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>可能涉及的相关知识产权情况
          <t-tooltip content="【应尽可能列出可能涉及的知识产权情况，包括采用其他标准涉及的版权情况，标准涉及专利情况等。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="intellectual">
            <InnerHtml :content="formData.intellectual"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>

      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>征求省有关部门或省级专业标准化技术委员会意见的情况
          <t-tooltip content="【标准化对象如涉及省有关部门或省级专业标准化技术委员会，应征求并提供相关部门（省级专业标准化技术委员会）的意见。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="idea">
            <InnerHtml :content="formData.idea"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>
      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>经费预算
          <t-tooltip content="【应包括制定标准所需经费总额、政府补助经费、自筹经费的情况。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="budget">
            <InnerHtml :content="formData.budget"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>

      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>项目进度安排
          <t-tooltip content="【标准进度一般按照标准制修订程序的各个阶段进行，应制定详细的工作计划，根据制修订周期细化组织起草、征求意见、技术审查等各阶段具体时间安排。】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="schedule">
            <InnerHtml :content="formData.schedule"></InnerHtml>
          </t-form-item>
        </t-col>
      </t-row>

      <t-row style="min-height: 200px">
        <t-col :span="2" class="title"><span class="require">*</span><span>需要申报的其他事项
          <t-tooltip content="【需要废止或修订其他标准的建议，以及其他需要说明的事项】">
            <t-icon name="help-circle-filled"></t-icon>
          </t-tooltip></span>
        </t-col>
        <t-col :span="10">
          <t-form-item name="other">
            <InnerHtml :content="formData.other"></InnerHtml>

          </t-form-item>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>相关附件</t-col>
        <t-col :span="10">
          <t-table size="small" row-key="id" :columns="projectFileColumns" :data="projectFileData">
            <template #id="{row, rowIndex}">
              {{ rowIndex+1 }}
            </template>
            <template #c1="{row}">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
            <template  #op="{row}">
              <file-upload
                v-if="['projectSBB'].includes(row.moduleKey) && $store.state.user.roles.includes('dwsby')"
                @success="uploadSuccess"
                tips="限制pdf、图片"
                accept="application/pdf,image/*"
                v-model="row.fileIds"
                :moduleKey="row.moduleKey"
                :fileList="row.fileLists"
                :multiple="true"
              >
                <t-button variant="outline">
                  <t-icon name="cloud-upload" slot="icon" />
                  点击上传
                </t-button>
              </file-upload>
              <div v-else v-for="(item,index) in row.fileLists" :key="index">
                <a class="t-button-link" target="_blank" :href="item.url" >
                  {{item.name}}
                </a>
              </div>
            </template>
          </t-table>
        </t-col>
      </t-row>
    </t-form>
  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import standardCompany from "@/pages/bzh/standard/components/standard-company.vue";
import InnerHtml from "@/components/InnerHtml/index.vue";
import {getFiles} from "@/api/common";
import FileUpload from '@/components/FileUpload/index.vue';


export default {
  name: "apply-detail",
  dicts: ['standard_property', 'formulate_type', 'bid_type', 'bid_degree', 'yes_or_not'],
  components:{
    standardCompany,
    InnerHtml,
    FileUpload,
  },
  data(){
    return {
      file_domain: VITE_FILE_DOMAIN,
      projectFileData: [
        // {
        //   id: 1,
        //   c1: "立项公文（盖章原件）",
        //   c2: "是",
        //   moduleKey: "projectLXGW",
        //   fileIds: [],
        //   fileLists: [],
        //   require: true,
        // },
        {
          id: 1,
          c1: "盖章后的申报表",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectSBB",
          require: true,
        },
        {
          id: 2,
          c1: "标准草案",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectBZCA",
          require: true,
        },
        {
          id: 3,
          c1: "编制说明",
          c2: "是",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectBZSM",
          require: true,
        },
        {
          id: 4,
          c1: "批复立项文件",
          c2: "否",
          fileIds: [],
          fileLists: [],
          moduleKey: "bzhlxpfwj",
          require: false,
        },
        {
          id: 5,
          c1: "其他",
          c2: "否",
          fileIds: [],
          fileLists: [],
          moduleKey: "projectOther",
          require: false,
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "附件列表",
          align: "left",
        },
      ],
      deptMenuOptions: [],
      formData: {
        localId: null,
        projectName: '',
        englishName: '',
        putDate: '',
        standardProperty: '',
        formulateType: '',
        reviseNum: '',
        manageDeptId: 100,
        bidCondition: {
          bidType: '',
          bidDegree: '',
          bidName: '',
          bidNum: '',
        },
        linkMan: '',
        linkWay: '',
        draftUnits: [],
        necessity: '',
        technicalContent: '',
        description: '',
        relation: '',
        catalogue: '',
        intellectual: '',
        idea: '',
        budget: '',
        schedule: '',
        other: '',
      },
    }
  },
  props: {
    objId: [String, Number],
    reviewOpen: {
      type: Boolean,
      default: false
    },
  },
  watch: {
    objId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getObj(val);
        }
      }
    },
  },
  created() {
    this.getDeptTreeSelect();
  },
  methods: {
    getDeptTreeSelect() {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getObj() {
      this.$api.bzh.standard.getApplyBySuggestId(this.objId).then(response => {
        if (response.data.createUserId === Number(this.$store.state.user.userId)) {
          this.isMyProject = true;
        }
        Object.assign(this.formData, response.data);
        getFiles(response.data.id).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData.forEach((val, index) => {
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
          })
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    uploadSuccess(ids) {
      this.$api.bzh.standard
        .updateBaseApply({
          id: this.formData.id,
          sysAttMainVo: {
            sysAttMainIds: ids,
          },
        })
        .then((val) => {
          this.$message.success('上传成功');
        })
        .catch((e) => {
          this.$message.error(e.toString());
        });
    },
  }
}
</script>

<style scoped>

</style>
